/**
 * 
 */
package com.cdhospital.websitecontroller;

import java.util.List;

import com.cdhospital.Model.News;
import com.cdhospital.adminservice.NewsService;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

/**
 * @author 17994
 *
 */
public class WebsiteNewsController extends Controller {
	static NewsService service=new NewsService();
	public void index(){String name=null;
	Integer pageNumber=getParaToInt("pageNum");
	Integer status=getParaToInt("status");
	if(pageNumber==null){
		pageNumber=1;
	}
	if(status==null){
		status=1;
	}
	if(status==1){
		name="机构动态";
	}
	else if(status==2){
		name="行业新闻";
	}
	else if(status==3){
		name="认识前列腺";
	}
	else if(status==4){
		name="前列腺炎";
	}
	else if(status==5){
		name="前列腺增生";
	}else if(status==6){
		name="前列腺癌";
	}else if(status==7){
		name="其他热点男科问题";
	}else if(status==8){
		name="前列腺疾病";
	}else if(status==9){
		name="性功能障碍";
	}else if(status==10){
		name="男性不育";
	}else if(status==11){
		name="生殖整形";
	}else if(status==12){
		name="其他";
	}else if(status==13){
		name="医保政策";
	}else if(status==14){
		name="学术交流";
	}else if(status==15){
		name="科研教学";
	}else if(status==16){
		name="护理园地";
	}else if(status==17){
		name="坚定荣誉";
	}else if(status==18){
		name="医保政策";
	}else if(status==19){
		name="发展历程";
	}else if(status==20){
		name="典型案例";
	}
	else if(status==21){
		name="常见问题";
	}
	else if(status==22){
		name="前例腺健康讲座";
	}
		setAttr("news", service.paginate(getParaToInt(0, pageNumber), 10, status));
		setAttr("status", status);
		setAttr("name", name);
		List<Record>  friendlinks=Db.findByCache("zone", "frindlink", "select * from friendlink order by flag asc");
		setAttr("firendlink", friendlinks);
		if(status>=1 && status<3){
			render("index.html");
		}else if(status>2 && status<8){
			render("index2.html");
		}
		else if(status>7 && status<13){
			render("index3.html");
			
		}
		else if(status>12 && status<14){
			render("index4.html");
		}
		else if(status>13 && status<15){
			render("index5.html");
		}
		else if(status>14 && status<16){
			render("index6.html");
		}
		else if(status>15 && status<17){
			render("index7.html");
		}
		else if(status>16 && status<22){
			render("index8.html");
		}
		
	}
	public void form (){
		Integer pageNumber=getParaToInt("pageNumber");
		
		if(pageNumber==null){
			pageNumber=1;
		}
		
		Integer id=getParaToInt("id");
		if (id!=null && id>0) {
			News news=service.findById(id);
		    int num=	news.getNum();
		   num++;
		   news.setNum(num);
		   news.update();
			setAttr("news", service.findById(id));
		}
		List<Record>  friendlinks=Db.findByCache("zone", "frindlink", "select * from friendlink order by flag asc");
		setAttr("firendlink", friendlinks);

		render("indexform.html");
	}

}
